package com.freestyle.nettychat.chat.dto;

import com.freestyle.nettychat.chat.CodeConsts;

/**
 * Created by rocklee on 2022/2/5 14:22
 */
public class CommandMessage extends ChatMessage<String> {
  private static final ThreadLocal<Long> localLong=new ThreadLocal<>();
  public static long getLastId(){
    return localLong.get();
  }
  public static CommandMessage fromCommand(long id,String uuid,String text){
    localLong.set(id);
    ChatMessageProperties properties=new ChatMessageProperties();
    properties.setId(id);
    properties.setUuid(uuid);
    properties.setSClass(CodeConsts.MessageType.command.toString());
    CommandMessage commandMessage=new CommandMessage();
    commandMessage.setProperties(properties);
    commandMessage.setData(text);
    return commandMessage;
  }
  public static CommandMessage fromMessage(ChatMessage message){
    CommandMessage commandMessage=new CommandMessage();
    commandMessage.setProperties(message.getProperties());
    commandMessage.getProperties().setSClass(CodeConsts.MessageType.command.toString());
    commandMessage.setData((String) message.getData());
    return commandMessage;
  }
}
